package com.vincent.suchao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vincent.suchao.entity.MyContacts;
import com.vincent.suchao.entity.MyContacts.ContactItem;
import com.vincent.suchao.lcld.R;

public class ContactsAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater mInflater;
	MyContacts myContacts;

	public ContactsAdapter(Context mcontext) {
		super();
		this.context = mcontext;
		this.mInflater = LayoutInflater.from(context);
		this.myContacts = new MyContacts(mcontext);
	}

	@Override
	public int getCount() {
		return myContacts.getContacts().size();
	}

	@Override
	public Object getItem(int position) {
		return myContacts.getContacts().get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ContactItem menuItem = (ContactItem) myContacts.getContacts().get(position);

		MyHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.inflater_contact_item, null);
			holder = new MyHolder();

			holder.rl_inflater_contact = (RelativeLayout) convertView.findViewById(R.id.rl_inflater_contact);
			holder.iv_contact_icon = (ImageView) convertView.findViewById(R.id.iv_contact_icon);
			holder.tv_contact_content = (TextView) convertView.findViewById(R.id.tv_contact_content);

			convertView.setTag(holder);
		} else {
			holder = (MyHolder) convertView.getTag();
		}
		holder.rl_inflater_contact.setTag(R.id.rl_inflater_contact, menuItem);
		holder.iv_contact_icon.setImageResource(menuItem.getResID());
		holder.tv_contact_content.setText(menuItem.getContent());

		return convertView;
	}

	class MyHolder {
		RelativeLayout rl_inflater_contact;
		ImageView iv_contact_icon;
		TextView tv_contact_content;

	}

}
